<?php

/*
 * 公共类
 *
 *
 *
 */

class PublicAction extends Action {

    public function login() {
        if ($_SESSION[C('ADMIN_SESSION_KEY')]) {
            $this->redirect('Index/index');
        } else {
            $this->display();
        }
    }

    public function checklogin() {
        if ($_SESSION['verify'] == md5($_POST['verify'])) {
            $dao = M('Admin');
            $uname = $_POST['username'];
            $pwd = $_POST['password'];
            $user = $dao->where('username ="'.$uname.'"')->find();
            if ($user['password'] == md5($pwd)) {
                $_SESSION[C('ADMIN_SESSION_KEY')] = $user['id'];
                $_SESSION['username'] = $user['username'];
                $_SESSION['level'] = $user['level'];
                $_SESSION['expire_time'] = time();
                $this->ajaxReturn('',$Think.lang.loginsuccess, 1);
            } else {
                $this->ajaxReturn('', $Think.lang.loginerror, 0);
            }
        } else {
            $this->ajaxReturn('', $Think.lang.enterver, 0);
        }
    }

    public function logout() {
        if ($_SESSION[C('ADMIN_SESSION_KEY')]) {
            session_destroy();
            $this->assign('jumpUrl', U('Index/index'));
            $this->success('您已經成功退出！');
        } else {
            $this->assign('jumpUrl', U('Public/login'));
            $this->error('您還沒登陸');
        }
    }

    public function verify() {
        import ("Admin.ORG.Image");
        Image::buildImageVerify(4, 1);
    }

}

?>